package com.anche.demo.controller;


import com.anche.demo.entity.Son;
import com.anche.demo.entity.Student;
import com.anche.demo.entity.User;
import com.anche.demo.util.HttpDistribute;
import com.anche.demo.util.SpringContextUtil;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.context.request.RequestContextHolder;
import org.springframework.web.context.request.ServletRequestAttributes;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import java.util.Arrays;
import java.util.HashMap;

/**
 * @Classname UserController
 * @Description TODO
 * @Date 2022/11/27 11:58
 * @Created by Administrator
 */
@RestController
@RequestMapping("/student/")
@Slf4j
public class StudentController {



    @PostMapping("get")
    public String data(@RequestBody Student student) throws Exception {
        HttpServletRequest request = ((ServletRequestAttributes) RequestContextHolder.getRequestAttributes()).getRequest();
        String[] beanDefinitionNames = SpringContextUtil.getApplicationContext().getBeanDefinitionNames();
        Arrays.stream(SpringContextUtil.getApplicationContext().getBeanDefinitionNames()).forEach(System.out::println);

        StringBuffer url = request.getRequestURL();
        int localPort = request.getLocalPort();
        int remotePort = request.getRemotePort();
        int serverPort = request.getServerPort();
        String contextPath = request.getServletContext().getContextPath();
        String requestURI = request.getRequestURI();
        StringBuffer delete = url.delete(url.length() - request.getRequestURI().length(), url.length());
        String tempContextUrl = url.delete(url.length() - request.getRequestURI().length(), url.length()).append(request.getServletContext().getContextPath()).append(":").append(request.getServerPort()).append("/").toString();
        return student.getScore();
    }
    @PostMapping("get1")
    public String data1(@RequestBody Son student) throws Exception {
        System.out.println(student.getName());
        return student.getScore();
    }
    @PostMapping("get2")
    public String data2(@RequestBody Son son) throws Exception {
        System.out.println();
        return son.getScore();
    }
}